package com.hm.fleaMarket.controller;

import com.hm.fleaMarket.service.AdminService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author HM
 * @create 2018/2/27 14:41
 * @desc
 **/
@Controller
public class AdminController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    AdminService adminService;

    @RequestMapping("/")
    public String index(){
        return "login";
    }

    @RequestMapping(value = "/admin/adminLogin",method = RequestMethod.GET)
    public String adminLogin(HttpServletRequest request,Model model){
        final String resutlts = null;
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if(adminService.selectAdminByUsernameAndPwd(username,password)){
            model.addAttribute("username",username);
            return "index";
        }
        return "login";
    }
}
